package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.User;
import com.cskaoyan.bean.wx_userindexVO.UserIndexVO;
import com.cskaoyan.service.UserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author 陈泉江
 * @version 1.0
 * @description: 显示用户的待做事项
 * @date 2021/6/7 15:03
 */
@RestController
public class WxUserIndexController {

    @Autowired
    UserService userService;

    //复用后台的UserController类
    @RequestMapping("/wx/user/index")
    public BaseRespVo userIndex() {

//        User user = new User();

        Subject subject = SecurityUtils.getSubject();
        Object subjectPrincipal = subject.getPrincipal();
        if (subjectPrincipal == null) {
            return BaseRespVo.fail("请登录后查看");
        } else {
            User user = (User) subjectPrincipal;
            UserIndexVO userIndexVO = userService.userIndex(user.getId());
            return BaseRespVo.ok(userIndexVO);
        }
    }
}
